package com.itxx.volatiles;
//用synchronized解决
public class Test1 {
    public static void main(String[] args) {


        BoyThread b = new BoyThread();
        b.start();
        GirlThread g = new GirlThread();
        g.start();

    }
}

class BoyThread1 extends Thread {
    @Override
    public void run() {
        synchronized (Monkey1.lock) {
            try {
                Thread.sleep(1);
                System.out.println("打游戏用了10000");
                Monkey.monkey = 90000;
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

class GirlThread1 extends Thread {


    @Override
    public void run() {
        while (true) {
            synchronized (Monkey1.lock){
                if (Monkey1.monkey==100000){
                    System.out.println("结婚");
                }else {
                    System.out.println("gun");
                    break;
                }
            }
        }
    }
}

class Monkey1 {
    public static Object lock = new Object();
    public static volatile int monkey=100000;

}

